package com.tim.app.ui.adapter.someone_homepage;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.application.library.widget.RatioImageView;
import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.constant.AppKey;
import com.tim.app.util.BitmapLoader;

import java.util.List;


/**
 * 相册
 */
public class AlbumAdapter extends BaseRecyclerAdapter<BaseRecyclerAdapter.BaseRecyclerViewHolder, String> {

    private Context mContext;

    public AlbumAdapter(Context mContext, List<String> mDataList) {
        super(mDataList);
        this.mContext = mContext;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseRecyclerViewHolder holder = null;
        holder = new InfoViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_album_item, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder mHolder, int position, final String data) {
        if (data == null) {
            return;
        }
        InfoViewHolder holder = (InfoViewHolder) mHolder;
        if (!TextUtils.isEmpty(data)) {
            if (data.equals(AppKey.ADD_PIC)) {
                holder.rlAddPic.setVisibility(View.VISIBLE);
                holder.rivAlbumPic.setVisibility(View.GONE);
            } else {
                holder.rlAddPic.setVisibility(View.GONE);
                holder.rivAlbumPic.setVisibility(View.VISIBLE);
                BitmapLoader.ins().loadImage(data, holder.rivAlbumPic);
            }
        } else {
            BitmapLoader.ins().loadImage("", holder.rivAlbumPic);
        }
    }

    public class InfoViewHolder extends BaseRecyclerViewHolder {

        RatioImageView rivAlbumPic;
        RelativeLayout rlAddPic;

        public InfoViewHolder(View itemView) {
            super(itemView);
            rivAlbumPic = (RatioImageView) itemView.findViewById(R.id.rivAlbumPic);
            rlAddPic = (RelativeLayout) itemView.findViewById(R.id.rlAddPic);
        }

    }

}
